<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>驳回订单</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layui/css/layui.css">
    <script src="layui/layui.js"></script>
</head>
<!-- L2Dwidget.js L2D网页动画人物 -->
<script src="https://eqcn.ajz.miesnfu.com/wp-content/plugins/wp-3d-pony/live2dw/lib/L2Dwidget.min.js"></script>
<script>
    L2Dwidget.init({
        "model": {
            "jsonPath": "https://unpkg.com/live2d-widget-model-koharu@1.0.5/assets/koharu.model.json",
            "scale": 1,
            "hHeadPos": 0.5,
            "vHeadPos": 0.618
        },
        "display": {"position": "right", "width": 250, "height": 300, "hOffset": 0, "vOffset": 0},
        "mobile": {"show": true, "scale": 0.5},
        "react": {"opacityDefault": 0.7, "opacityOnHover": 0.2}
    });
</script>
<body>
<div style="margin: 0 40% ;color: #4E5465;font-size: 50px ">驳回出库单</div>
<script type="text/html" id="titleTpl">
    {{#  if(d.status ==2 ){ }}
    <button class="layui-btn layui-btn-sm layui-btn-danger">被驳回</button>
    {{#  } else { }}
    <%--<button class="layui-btn layui-btn-sm layui-btn-danger">下架</button>--%>
    {{#  } }}
</script>

<div class="demoTable" style="display: inline-block">
    <form id="AAA" style="display: inline-block">
        <div class="layui-inline">
            <input class="layui-input" name="o_orderid" placeholder="订单号" id="demoReload" autocomplete="off">
        </div>
        <div class="layui-inline">
            <input class="layui-input" name="o_name" placeholder="按销售人员查询" id="demoReload1" autocomplete="off">
        </div>
        <div class="layui-inline">
            <input class="layui-input" name="w_name" id="demoReload2" placeholder="按驳回人员查询" autocomplete="off">
        </div>
        <div class="layui-inline">
            <input type="date" class="layui-input" name="o_orderindate" id="demoReload3" placeholder="按销售单生成日期查询"
                   autocomplete="off">
        </div>
    </form>
    <button class="layui-btn" data-type="reload"><i class="layui-icon layui-icon-search"></i></button>
</div>
<button class="layui-btn" data-type="reload" id="btn1"><i class="layui-icon layui-icon-refresh"></i></button>

<table class="layui-hide" id="test" lay-filter="test"></table>
<div id="up" style="display: none">
    <table class="layui-hide" id="test1" lay-filter="test1"></table>
</div>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">提交</button>
    </div>
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="sub">再提交</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="information">修改订单信息</a>
</script>


<script src="layui/layui.js" charset="utf-8"></script>


<script>
    layui.use(['table', 'jquery', 'form', 'layer'], function () {
        var table = layui.table;
        var $ = layui.jquery;
        var form = layui.form;
        var layer = layui.layer;

        function showTable() {
            table.render({
                elem: '#test'
                , url: '${pageContext.request.contextPath}/oorder/oorderstatus2'
                // , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                , defaultToolbar: ['filter', 'exports', 'print', { //自定义头部工具栏右侧图标。如无需自定义，去除该参数即可
                    title: '提示'
                    , layEvent: 'LAYTABLE_TIPS'
                    , icon: 'layui-icon-tips'
                }]
                , title: '用户数据表'
                , cols: [[
                    {type: 'checkbox', fixed: 'left'}
                    , {field: 'o_orderid', title: '订单id', sort: true, fixed: 'left'}
                    , {field: 'o_name', title: '销售人员', sort: true, fixed: 'left'}
                    , {field: 'w_name', title: '驳回人员', sort: true, fixed: 'left'}
                    , {field: 'status', title: '订单状态', sort: true, templet: '#titleTpl'}
                    , {field: 'o_orderindate', title: '订单发布日期'}
                    , {field: 'bh', title: '驳回原因', sort: true}
                    , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 200}
                ]]
                , page: true
                , id: 'testReload'
                , limit: 3
                , limits: [3, 5, 8, 10]
            });
        }


        $(function () {
            showTable();

        });

        //点击刷新按钮时刷新页面
        $(document).on('click', '#btn1', function () {

            showTable();
            $("#AAA")[0].reset();

        });

        //条件查询的重载
        var $ = layui.$, active = {
            reload: function () {
                var demoReload = $('#demoReload').val();
                var demoReload1 = $('#demoReload1').val();
                var demoReload2 = $('#demoReload2').val();
                var demoReload3 = $('#demoReload3').val();
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where: {
                        o_orderid:demoReload,
                        o_name: demoReload1,
                        w_name: demoReload2,
                        o_orderindate: demoReload3
                    }
                }, 'data');
            }
        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });


        table.on('edit(test1)', function (obj) { //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data;
            var reg = /^[1-9]\d*$/;
            if (!reg.test(obj.value)) {
                layer.msg("数量为正整数!", {icon: 5, anim: 6});
            }
        });

//头工具栏事件
        table.on('toolbar(test1)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'getCheckData':
                    var data = checkStatus.data;
                    $.ajax({
                        type: 'post',
                        url: '${pageContext.request.contextPath}/oorder/updateReject',
                        data: JSON.stringify(data),
                        contentType: 'application/json;charset=utf-8',
                        success: function (result) {
                            layer.closeAll();
                            if (result.code == 1) {
                                layer.msg(result.msg, {icon: 1});
                                showTable();
                            } else {
                                layer.msg(result.msg, {icon: 5});
                            }
                        }

                    });
                    break;

            }


        });


        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            //console.log(obj)
            if (obj.event === 'sub') {
                $.ajax({
                    type: 'post',
                    url: '${pageContext.request.contextPath}/oorder/setStatus0',
                    data: {o_orderid: data.o_orderid},
                    dataType: 'json',
                    success: function (result) {
                        if (result.code == 1) {
                            layer.msg(result.msg, {icon: 1});
                            showTable();
                        } else {
                            layer.msg(result.msg, {icon: 5});
                        }
                    }
                });
            } else if (obj.event === 'information') {
                //订单详情回显
                //修改
                layer.open({
                    type: 1,
                    title: "标题",
                    fixed: true,
                    resize: false,
                    totalRow: true,
                    area: ['950px', '400px'],
                    content: $('#up'),
                    success: function () {
                        table.render({
                            id: 'idSc',
                            elem: '#test1'
                            , method: 'post'
                            , url: '${pageContext.request.contextPath}/oorder/queryById?o_orderid=' + data.o_orderid
                            , toolbar: '#toolbarDemo'
                            , title: '用户数据表'
                            , totalRow: true
                            , cols: [[
                                {type: 'checkbox', fixed: 'left'}
                                // ,{field:'id', title:'ID', width:80, fixed: 'left', unresize: true, sort: true, }
                                , {
                                    field: 'o_orderid',
                                    title: '订单ID',
                                    fixed: 'left',
                                    unresize: true,
                                    sort: true,
                                    totalRowText: '合计'
                                }
                                , {field: 'bookname', title: '书名'}
                                , {field: 'author', title: '作者'}
                                , {field: 'press', title: '出版社'}
                                , {field: 'count', title: '库存'}
                                , {field: 'ocount', title: '采购数量', totalRow: true, edit: 'text', event: 'edit'}
                                , {field: 'o_price', title: '金额', totalRow: true}
                            ]]
                            , page: false
                        });

                    }
                });
            }
        });
    });

</script>

</body>
</html>